package datastruct;

public class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}


// java只有值传递，值是地址
class Test {
    public static void main(String[] args) {
        ListNode head = new ListNode(0);
        ListNode p1 = new ListNode(1, head);
        ListNode p2 = new ListNode(2, p1);
        // 0 -> 1 -> 2
        ListNode cur = head;
        System.out.println(cur);
        System.out.println(head);
        cur = p1;
        System.out.println(cur);
        System.out.println(head);

        ListNode t;
        t = head;
        System.out.println(t);
        t = p1;
        System.out.println(t);
        System.out.println(head);

        //change val
        cur = head;
        cur.val = 100;
        System.out.println(head.val);
    }
}